import { randomNumber } from "mmb"
import { AppCTX } from "../../types/koaExtend";
import { createSpokesmanApiMWRouter } from "../../middleware/spokesman-api/brandSpokesmanChecker";
const router = createSpokesmanApiMWRouter();


// 新增品牌代言人申请
router.post("/spn/:spokemanId/brandEndorseRequest", async (ctx: AppCTX, next) => {
  const { spokemanId } = ctx.params;
  const { brandId, brandEndorsementId, applyField, message } = ctx.request.body;
  const { userId } = ctx;
  let auditResult = 'pending'
  // 如果商家代言设置了自动审核通过,需要立即更新代言请求的结果
  let autoApprove = Number(randomNumber(2)) % 2 === 0
  if (autoApprove) {
    auditResult = 'approved'
  }
  ctx.body = {
    spokemanId,
    userId, //操作人
    endorseRequestId: (101).toString(),
    brandId, 
    brandEndorsementId,
    applyField, 
    message,
    auditResult
  };
});


export default router;